window.onload = function(){	

	// 设置超链接获取关键字
	var url;
	var val;
	var keyWord;
	function setandgetvalue(){
		keyWord = solorBox.value;								
			if(val=="百度"){					
				url = "https://www.baidu.com/s?wd=" + keyWord;
			}else if(val=="google"){
				url = "https://www.google.com/search?source=hp&ei=KNEnWqOFIIGu0gS2zZzYDQ&q=" + keyWord;
				}else if(val=="找字形"){
				url = "http://www.ziticq.com/Works/k/" + keyWord;
			}else if(val=="找样机"){
				url = "http://www.ziticq.com/Material/k/" + keyWord;
			}else if(val=="Dribbble"){
				url = "https://dribbble.com/search?q=" + keyWord;
			}else if(val=="Behance"){
				url = "https://www.behance.net";
			}else if(val=="Icon"){
				url = "https://www.iconfont.cn/search/index?searchType=icon&q=" + keyWord;
			}else if(val=="花瓣"){
				url = "https://huaban.com/search/?q=" + keyWord;
			}else{
				url = "https://www.baidu.com/s?wd=" + keyWord;
			}
	}
	// /设置超链接获取关键字
	
// 导航搜索的实现
	var divvs = $('.nav ul li');
	var solorBox = document.getElementsByClassName("solor-box")[0];	
	
	for(var i = 0; i < divvs.length; i++){
		divvs[i].onclick = function(){
			val = this.innerText;			
			if(val=="百度"){					
				solorBox.placeholder="百度一下";
			}else if(val=="google"){
				solorBox.placeholder="google";
			}else if(val=="找字形"){
				solorBox.placeholder="找字形";
			}else if(val=="找LOGO"){
				solorBox.placeholder="找LOGO";
			}else if(val=="找样机"){
				solorBox.placeholder="找样机";
			}else if(val=="Dribbble"){
				solorBox.placeholder="Dribbble";
			}else if(val=="Behance"){
				solorBox.placeholder="Behance";
			}else if(val=="Icon"){
				solorBox.placeholder="Icon";
			}else if(val=="花瓣"){
				solorBox.placeholder="花瓣";
			}else if(val==""){
				solorBox.placeholder="请输入您要搜索的关键字";
			}
			
			for(var j=0;j<divvs.length; j++){
                divvs[j].setAttribute("id","defausty");
			}
			
			this.setAttribute("id","sty");
					
			document.getElementsByClassName("solor-go")[0].onclick = function(){
				setandgetvalue();						
				window.open(url,'_block');								
			};

            // 回车键功能
			document.onkeydown = function(e){
				setandgetvalue();
				if (!e) e = window.event; 
            	if ((e.keyCode || e.which) == 13) {
               	 window.open(url,'_block');
            	}			  
			};
			// /回车键功能
		}		
	}
	document.getElementsByClassName("solor-go")[0].onclick = function(){
		keyWord = solorBox.value;		
		url = "https://www.baidu.com/s?wd=" + keyWord;							
		window.open(url,'_block');	
	};	
	// 回车键功能
	document.onkeydown = function(e){
		keyWord = solorBox.value;		
		url = "https://www.baidu.com/s?wd=" + keyWord;		
		if (!e) e = window.event; 
    	if ((e.keyCode || e.which) == 13) {
       	 window.open(url,'_block');
    	}			  
	};
	// /回车键功能
	// /导航搜索的实现
		
	// 左侧导航滚动固定的实现
	   var oDiv = document.getElementById("left-nav"),
			H = 0,
			Y = oDiv;        
		while (Y) {
			H += Y.offsetTop; 
			Y = Y.offsetParent;
		}
		window.onscroll = function(){
			var s = document.body.scrollTop || document.documentElement.scrollTop;
			if(s>=H) {
				oDiv.style = "position:fixed;top:1px;background:none;";
			} else {
				oDiv.style = "";
			}
		}

	// /左侧导航滚动固定的实现
	 
	//左侧导航栏链接的实现
	var lnavs = $('#left-nav a');
	var lnavsli = $('#left-nav a li');
	var sections = $('.free-font'); 
	var reg = "autoHref";
	var linkId = "";

	for (var k = 0; k < lnavs.length; k++) {
		linkId = reg + k;
		sections[k].setAttribute("id", linkId);		
		lnavs[k].href = ("#" + sections[k].id);		
	}	
	// /左侧导航栏链接的实现
	
	// 滑动置顶的实现
    $('#toTop').click(function(){
        $('html, body').animate({
            scrollTop: 0
        }, 800);
    }); 
    // 滑动置顶的实现
	
	// 左侧导航栏跟随滑动定位的实现
	var nav = $('#left-nav');
    var mainPage = $('.free-font');
    var mainTopArr = new Array();
    var top = 0;
    for(var i = 0;i < mainPage.length; i++){
        top = mainPage.eq(i).offset().top;
        mainTopArr.push(top);
    }
    $(window).scroll(function(){
        var scrollTop = $(this).scrollTop();
        var p = 0;
        for(var i=0;i<mainTopArr.length;i++){
            if(scrollTop>=mainTopArr[i]){
            	p=i+1;               
            }
        }
		nav.find('a').eq(p).addClass('active').siblings().removeClass('active');
    });
    nav.find("a[href^='#']").click(function(e){
        e.preventDefault();
        $('html, body').animate({scrollTop: $(this.hash).offset().top}, 500);
    });	
    // 左侧导航栏跟随滑动定位的实现
};
